﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Tunnel_Cross_Section
{
    static class Program
    {
        [DllImport("User32.dll")]
        //调用API SendMessage函数!!
        private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {

            Mutex onlyOne= new Mutex(true, Process.GetCurrentProcess().ProcessName);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //try  
            {
                if (onlyOne.WaitOne(0, false))
                {
                    //程序第一次运行
                    Mfrm frm = new Mfrm();
                    Application.Run(frm);
                }
                else
                {
                    //"程序已经运行!"
                    string name = Process.GetCurrentProcess().ProcessName;
                    IntPtr hwnd = Process.GetProcessesByName(name)[0].MainWindowHandle;
                    //发送指令让程序最大化!
                    SendMessage(hwnd, 274, 61488, 0);


                }
            }
            //catch (Exception e) 
            //{
            //    MessageBox.Show(e.Message);
            //}
        }
    }
}